const Sequelize = require('sequelize');
const fs = require('fs');
const { sqlConfig } = require('../config');

const models = {};
// 数据库连接
const sequelize = new Sequelize(sqlConfig.database, sqlConfig.username, sqlConfig.password, {
    host: sqlConfig.host,
    dialect: sqlConfig.type,
    pool: sqlConfig.pool
});

// 遍历模型并创建
fs.readdirSync(`${__dirname}/../models`).forEach((modelName) => {
    modelName = modelName.split('.js')[0];
    const model = require(`${__dirname}/../models/${modelName}`);
    models[modelName] = sequelize.define(modelName, model.fields(Sequelize), model.configs);
});

module.exports = models;







